/*
 * Filename:    CodeLabelServiceImpl.java
 * Copyright:   2014 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2014年10月15日
 */
package com.paic.mhis.hcpms.quota.settlement.intergration.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.paic.mhis.hcpms.quota.indicatorconfig.dto.IndicatorBaseDTO;
import com.paic.mhis.hcpms.quota.settlement.dto.CodeLabelDTO;
import com.paic.mhis.hcpms.quota.settlement.dto.IndicationDeptDTO;
import com.paic.mhis.hcpms.quota.settlement.dto.IndicationDeptDoctor;
import com.paic.mhis.hcpms.quota.settlement.dto.IndicationOrgDepartment;
import com.paic.mhis.hcpms.quota.settlement.dto.MedicalOrgDTO;
import com.paic.mhis.hcpms.quota.settlement.intergration.dao.ICodeLabelDAO;
import com.paic.pafa.biz.dao.BaseDAO;

@Component("codeLabelDAOImpl")
public class CodeLabelDAOImpl extends BaseDAO implements ICodeLabelDAO {

	@Override
	public List<CodeLabelDTO> queryCodeLabelDTOByType(String type) {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("dictType", type);

		List<CodeLabelDTO> list = (List<CodeLabelDTO>) this._queryForList("costCover.queryCodeLabelDTO", map);

		return list;
	}

	/**
	 * 根据级别查询该级别下的所有医疗机构
	 * 
	 * @param level
	 * @return
	 */
	@Override
	public List<MedicalOrgDTO> queryMedicalOrgDTOByLevel(String level, int start, int end, String regionCode) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("level", level);
		map.put("start", start);
		map.put("end", end);
		map.put("regionCode", regionCode);
		List<MedicalOrgDTO> list = (List<MedicalOrgDTO>) this._queryForList("indication.queryMedicalOrgDTO", map);

		return list;
	}

	/**
	 * 查询医疗机构所有纪录-
	 */
	@Override
	public long queryMedicalOrgDTOCount(String level, String regionCode) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("level", level);
		map.put("regionCode", regionCode);
		long count = this._queryForCount("indication.queryMedicalOrgDTOAllRecord", map);

		return count;
	}

	/**
	 * 分页查询医疗机构下的科室信息
	 */
	@Override
	public List<IndicationOrgDepartment> queryIndicationOrgDepartmentByOrgCode(String orgId, int start, int end) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("orgId", orgId);
		map.put("start", start);
		map.put("end", end);
		List<IndicationOrgDepartment> list = (List<IndicationOrgDepartment>) this._queryForList(
				"indication.queryMedicalOrgDepartment", map);

		return list;
	}

	/**
	 * 查询医疗机构下所有的科室所有纪录
	 */
	@Override
	public long queryMedicalOrgDepartmentCount(String orgId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("orgId", orgId);

		long count = this._queryForCount("indication.queryMedicalOrgDepartmentAllRecord", map);

		return count;
	}

	/**
	 * 根据科室的编码查询科室下的医生信息
	 */
	@Override
	public List<IndicationDeptDoctor> queryIndicationDeptDoctorInfo(String deptId, int start, int end) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("deptId", deptId);
		map.put("start", start);
		map.put("end", end);
		List<IndicationDeptDoctor> list = (List<IndicationDeptDoctor>) this._queryForList(
				"indication.queryMedicalOrgDoctor", map);

		return list;
	}

	/**
	 * 根据科室编码查询该科室下医生总条目
	 */
	@Override
	public long queryIndicationDeptDoctorCount(String deptId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("deptId", deptId);

		long count = this._queryForCount("indication.queryMedicalOrgDoctorALLRecord", map);

		return count;
	}

	@Override
	public MedicalOrgDTO queryMedicalOrgDTOByOrgCode(String orgId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("orgId", orgId);
		List<MedicalOrgDTO> list = (List<MedicalOrgDTO>) this
				._queryForList("indication.queryMedicalOrgInfoByCode", map);

		if (list != null && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public IndicationDeptDTO queryIndicationDepartDTOByDeptCode(Map<String,Object> map) {
		
		List<IndicationDeptDTO> list = (List<IndicationDeptDTO>) this._queryForList("indication.queryDeptInfoByCode",
				map);

		if (list != null && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	/**
	 * 根据指标Id,加载指标信息
	 */
	@Override
	public IndicatorBaseDTO queryIndicatorBaseDTOByKpiId(String kpiId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("kpiId", kpiId);
		List<IndicatorBaseDTO> list = (List<IndicatorBaseDTO>) this._queryForList("costCover.queryIndicationBaseInfo",
				map);

		if (list != null && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}
}
